package wnhz.com.business.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import wnhz.com.business.R;
import wnhz.com.business.constants.Constants;
import wnhz.com.business.uitls.BroadCastReceiverUtil;
import wnhz.com.business.uitls.ToastUtils;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    private static final String TAG = "WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, "wxf698be257c5c06be");
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {

    }

    //处理微信支付回调
    @Override
    public void onResp(BaseResp resp) {

        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            if ("0".equals(String.valueOf(resp.errCode))) {
                ToastUtils.showToast(WXPayEntryActivity.this, "支付结果：" + "支付成功");
//                onPaySuccess();

//                BroadCastReceiverUtil.sendBroadcast(WXPayEntryActivity.this, Constants.ACTION_UPTATE_QIANBAOMONEY);
            } else if ("-1".equals(String.valueOf(resp.errCode))) {
                ToastUtils.showToast(WXPayEntryActivity.this, "支付结果：" + "支付失败");

            } else if ("-2".equals(String.valueOf(resp.errCode))) {
                ToastUtils.showToast(WXPayEntryActivity.this, "支付结果：" + "取消支付");

            }
            finish();

        }

    }
}